<?
require_once dirname(__FILE__).'./hyang/ConeroClass.php';
require_once dirname(__FILE__).'./hyang/config/config.ini.php';

function my_autoloader($url) 
{
    include $url;
}
function Zonetime($zone)//显示不同时区的时间
{
	$dateSrc = date('Y-m-d H:i:s',time());
	if($zone == '')
	{
		return $dateSrc;
	}
   date_default_timezone_set($zone);
   return date('Y-m-d H:i:s',time());
}

function sys_date($format=null)
{
	$format = (($format == true)? 'Y-m-d' : $format);
	if($format)
	{
		if(date($format,time()))
		{
			return date($format,time());
		}
		return false;
	}
	else
	{
		return date('Y-m-d H:i:s',time());
	}
}
//2015/12/21 星期一
/*
 *	$method:class 面向对象风格；其他：过程化风格
 *
 *
 */
function date2add($date,$n=0,$format='D',$method='class')
{
	if($method != 'class')
	{
		if($format == 'D') $format = ' days';
		$tmpDate = date_create($date);
		date_add($tmpDate, date_interval_create_from_date_string($n.$format));
		return date_format($tmpDate,'Y-m-d');
	}
	$tmpDate = new DateTime($date);
	$tmpDate->add(new DateInterval('P'.$n.$format));
	return $tmpDate->format('Y-m-d');
}
//2015/12/21 星期一	diff = d2-d1
function date2diff($date1,$date2,$format='D',$method='class')
{
	if($method != 'class')
	{
		$d1 = date_create($date1);
		$d2 = date_create($date2);
		$interval = date_diff($d1,$d2);
		$diff = $interval->format('%a');
	}
	$d1 = new DateTime($date1);
	$d2 = new DateTime($date2);
	$interval = $d1->diff($d2);
	$diff = $interval->format('%a');
	return abs($diff);
}

function getRealIpAddr()//获取真实的ip
{
	return getIp();
}
// 简化 getRealIpAddr() 函数名称
function getIp()
{
	if (!empty($_SERVER['HTTP_CLIENT_IP']))
	{
		$ip=$_SERVER['HTTP_CLIENT_IP'];
	}
	elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
	//检查IP是从代理传递
	{
		$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	else
	{
		$ip=$_SERVER['REMOTE_ADDR'];
	}
	return $ip;
}



//检测为移动设备
function isMobile()
{ 
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
        return true;
    } 
    // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
    { 
        // 找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    } 
    // 判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT']))
    {
        $clientkeywords = array ('nokia','sony','ericsson','mot','samsung','htc','sgh','lg','sharp','sie-','philips','panasonic','alcatel','lenovo','iphone','ipod','blackberry','meizu','android','netfront','symbian','ucweb','windowsce','palm','operamini','operamobi','openwave','nexusone','cldc','midp','wap','mobile'); 
        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
        {
            return true;
        } 
    } 
    // 协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT']))
    { 

        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
        {
            return true;
        } 
    } 
    return false;
} 

//$title 在头文件插入array('type'=>'{json}');array('type'=>'filename','title'=>'网页标题'),type:Mob,Web;json=>{'css':'fname1','csses':'fname1,fname2,..','js':'fname1','jses':'fname1,fname2,..'}
function htmlHead($title)//HTML网页头部声明  公共头部  -不含</head>
{
	//移动端web开发
	if(isMobile()){
		require_once(dirname(__FILE__)."/mobile/index.php");
		die;
	}
	$user = (isset($_SESSION['user'])? TITLEPER.$_SESSION['user'].' ' : TITLE);
	$JqueryUI = '
		<script src="'.ROOT.'public/js/jquery-2.1.4.min.js"></script>
		<script src="'.ROOT.'public/jqueryui/jquery-ui.min.js"></script>
		<link rel="stylesheet" type="text/css" href="'.ROOT.'public/jqueryui/jquery-ui.min.css">
		<link rel="stylesheet" type="text/css" href="'.ROOT.'public/jqueryui/jquery-ui.theme.min.css">
		<link rel="stylesheet" type="text/css" href="'.ROOT.'public/jqueryui/jquery-ui.structure.min.css">
		<script src="'.ROOT.'public/js/Hyang.js"></script>
	';
	$mobile = '
		<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<meta name="viewport" content="width=device-width"><head>
	';
	$wed = '
		<!DOCTYPE html>
		<html>
		<head>
		<link rel="shortcut icon" href="'.P.'image/Doee.ico"/>
		<link rel="bookmark" href="'.P.'image/Doee.ico""/>
	';
	if(is_array($title))
	{
		echo isMobile() ? $mobile.$JqueryUI.'<title>'.$user.$title['title'].'[Mobile]</title>' : $wed.$JqueryUI.'<title>'.$user.$title['title'].'[Web]</title>';
		if(isset($title['Mob']) && isMobile())
		{
			$mobArr = json_decode($title['Mob'],true);
			isset($mobArr['js']) ? improt('js',$mobArr['js']) : '';
			isset($mobArr['css']) ? improt('css',$mobArr['css']) : '';
			if(isset($mobArr['jses']))
			{
				foreach(explode(',',$mobArr['jses']) as $value)
				{
					improt('js',$value);
				}
			}
			if(isset($mobArr['csses']))
			{
				foreach(explode(',',$mobArr['csses']) as $value)
				{
					improt('css',$value);
				}
			}
		}
		else if(isset($title['Web']) && !isMobile())
		{
			$webArr = json_decode($title['Web'],true);
			isset($webArr['js']) ? improt('js',$webArr['js']) : '';
			isset($webArr['css']) ? improt('css',$webArr['css']) : '';
			if(isset($webArr['jses']))
			{
				foreach(explode(',',$webArr['jses']) as $value)
				{
					improt('js',$value);
				}
			}
			if(isset($webArr['csses']))
			{
				foreach(explode(',',$webArr['csses']) as $value)
				{
					improt('css',$value);
				}
			}
		}
	}
	else
	{	
		echo isMobile() ? $mobile.$JqueryUI.'<title>'.$user.$title.'[Mobile]</title>' : $wed.$JqueryUI.'<title>'.$user.$title.'[Web]</title>';
	}
	
}
//2015/12/10 星期四  插件
function plugin($name)
{
	$html = false;
	if($name == 'markup')
	{
		$html = '
			<link rel="stylesheet" type="text/css" href="'.ROOT.'/public/markitup/images/style.css">
			<link rel="stylesheet" type="text/css" href="'.ROOT.'/public/markitup/markitup/skins/markitup/style.css">
			<link rel="stylesheet" type="text/css" href="'.ROOT.'/public/markitup/markitup/sets/default/style.css">
			<script type="text/javascript" src="'.ROOT.'/public/markitup/markitup/jquery.markitup.js"></script>
			<script type="text/javascript" src="'.ROOT.'/public/markitup/markitup/sets/default/set.js"></script>
		';
	}
	if($name == 'tinymce')
	{
		$html = '
			<script src="'.ROOT.'public/tinymce/tinymce.min.js"></script>
		';
	}
	return $html;
}

//2015/12/16 星期三		PHP 导入libs文件下的引用包
function extension($name = null)
{
	$dir = dirname(__FILE__).'./libs/'.$name.'/'.$name.'.php';

	if(is_file($name))	require_once $name;	//支持 url

	if(is_file(dirname(__FILE__).$name))	require_once dirname(__FILE__).$name;	//支持 url

	if(is_file($dir))
	{
		require_once $dir;	//默认libs下同名文件
		
		if($name == 'PHPExcel')
		{//PHPExcel  加载类   附加
			require_once dirname(__FILE__).'./libs/'.$name.'/PHPExcel/IOFactory.php';
		}
	}
}
//2016/1/8 星期五		减少页面跳转页面witch语句的负担，使程序简洁化程序
/*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
//控制器跳转		php->eval 函数的使用
function pageTo($app,$sid=null,$debug=null)
{
	$php = "\$".$app." = new ".$app."();\n"."\$".$app." = new ".$app."();\n"."\$".$app.' -> '.$sid."();\n"."\$".$app.' -> index();\n';
	if($debug) return $php;
	eval($app."= new ".$app."();");
	eval("\$".$app." = new ".$app."();");
	if($sid){
		eval("\$".$app.' -> '.$sid.'();');
	}
	else{
		eval("\$".$app.' -> index();');
	}
	
}
//模式跳转
function modelTo($method,$debug=null)
{
	if($method == '') return;
	$php = '$model = new model();'."\n".'$model->'.$method.'();'."\n";
	if($debug) return $php;
	eval('$model = new model();');
	eval('$model->'.$method.'();');
}
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/

/*
*
*$array('name'=>$name,'int'=>$int[,'option'=>$option])string-int-string(连接值)/string -int
*/
function Create_select($array)
{
	if(is_array($array))
	{
		if(!isset($array['option']))
		{
			$option = '';
			for($i=0; $i<$array['int'] ;$i++)
			{
				$option = $option.'<option value="'.($i+1).'">'.($i+1);
			}
			return '<select name="'.$array['name'].'">'.$option.'</select>';
		}
		else
		{
			return false;//待写
		}
	}
	elseif(is_int($array))
	{
		$option = '';
		for($i=0; $i<$array; $i++)
		{
			$option = $option.'<option value="'.($i+1).'">'.($i+1);
		}
		return $option;
	}
	else
	{
		return false;
	}
}

function view($filename)//加载视图文件
{
	if($filename != '')
	{
		$file = './public/view/'.$filename;
		if(is_file($file))
		{
			include $file;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	
}
//自动加载app下文件
function app($name)
{
	$url = './hyang/app/'.$name.'/';
	$c = new C();
	$data = $c->printDir($url);
	$data['url'] = $url;
	return $data;
}
function loadApp($name)
{
	$dir = './hyang/app/'.$name.'/';
	if(is_dir($dir))
	{
		if ($dw = opendir($dir))
		{
			//require_once dirname(__FILE__).'./hyang/ControllerAbstract.php';
			require_once str_replace('\\','/',dirname(__FILE__).'./hyang/ControllerAbstract.php');
			require_once str_replace('\\','/',dirname(__FILE__).'./hyang/ModelAbstract.php');
			//require_once str_replace('\\','/',dirname(__FILE__).'./hyang/ViewAbstract.php');  视图有点多余-遂其除掉
			while(($fscan = readdir($dw)) !== false)
			{
				if(strlen($fscan)>3) require_once $dir.$fscan;
			}
		}
		return;
	}
	else return false;
}

function improt($type,$file)//加载public下面的文件
{
	$type = strtolower($type); 
	switch ($type)
	{
		case 'css':
			if(is_file('./public/css/'.$file) || is_file('./public/css/'.$file.'.css'))
			{
				if(stripos($file,'.css'))
				{
					echo '<link rel="stylesheet" type="text/css" href="./public/css/'.$file.'">';
				}
				else
				{
					echo '<link rel="stylesheet" type="text/css" href="./public/css/'.$file.'.css">';
				}
				return true;
			}
			break;
		case 'js':
			if(is_file('./public/js/'.$file) || is_file('./public/js/'.$file.'.js'))
			{
				if(stripos($file,'.js'))
				{
					echo '<script src="./public/js/'.$file.'"></script>';
				}
				else
				{
					echo '<script src="./public/js/'.$file.'.js"></script>';
				}
				return true;
			}
			break;
		case 'php':
			if(is_file('./public/model/'.$file) || is_file('./public/js/'.$file.'.php'))
			{
				if(stripos($file,'.php'))
				{
					include './public/model/'.$file;
				}
				else
				{
					include './public/model/'.$file.'.php';
				}
				return true;
			}
			break;
			break;
		case 'view':
			include './public/view/'.$file;
			break;
		default:
			return false;
	}
}

//2015/12/25 星期五		新的加载方法
/*
 *	
 *
 */
function import($app,$name,$type='view')
{
	if($type != 'view')
	{
		echo (($type == 'css')? '<link rel="stylesheet" type="text/css" href="'.ROOT.'public/css/app/'.$app.'/'.$name.'.css">':'<script src="'.ROOT.'public/js/app/'.$app.'/'.$name.'.js"></script>');
	}
	else
	{
		$url = './hyang/view/'.$app.'/'.$name.'.html';
		if(is_file($url)) {
			include $url;
			return true;
		}
		elseif(is_file(dirname(__FILE__).'/hyang/view/'.$app.'/'.$name.'.html')){
			include dirname(__FILE__).'/hyang/view/'.$app.'/'.$name.'.html';
			return true;
		}
		else{
			//return $url;
			return false;
		}
	}
}
function virtualDb($type,$file,$en=null)//virtualdb 文件下虚拟数据库
{//echo dirname(__FILE__);die;
	$en = $en? str_replace('\\','/',dirname(__FILE__)) : '.';
	switch ($type)
	{
		case 'data':
			$url = $en.'/virtualdb/'.$type.'/'.$file;
			if(is_file($url))
			{
				return $url;
			}
			return false;
			break;
		default:
			$url = $en.'/virtualdb/'.$file;
			if(is_file($url))
			{
				return $url;
			}
			return false;
	}
}
function db()//虚拟数据库-用户存放管理员的信息
{
	$array = array(
		'admin'=>'hyang',
		'EmmaWang'=>'1994@0123'
	);
	return $array;
}
//--该系统专用
function print_dir($dir,$feekback=null)
{	//header('Content-type: text/html; charset=utf-8');
	$files = array();
	//print_r(opendir( $dir ));
	
	if ( $dw = opendir( $dir ) )
	{
		while (($ctt = readdir($dw)) !== false)
		{
			$files[] = $ctt;
			$pat = "/^[0-9]+$/";
			if(preg_match($pat,$ctt))
			{
				$furl = $dir."/".$ctt;
				if ( $fs = opendir( $furl ) )
				{
					while(($fscan = readdir($fs)) !== false)
					{
						if(strlen($fscan)>3)
						{
							$link = $furl."/".$fscan;
							$tmp = $fscan;
							$filename = explode(".",$tmp);
							if(count($filename) > 2)
							{
								$n = count($filename) - 1;
								unset($filename[$n]);
								$stem = implode('.',$filename);
							}
							else
							{
								$stem = $filename[0];
							}
							//echo"<p><a href='".$link."' style='text-decoration:none;background:lime;border:1px solid black;'>[ ".$ctt." ] ".$stem."</a>";
							//echo"updown.php
							if(empty($feekback)){
								echo"<p><a href='updown.php?sid=".$link."' style='text-decoration:none;background:lime;border:1px solid black;'>[ ".$ctt." ] ".$stem."</a>";
								echo"<a><a href='upfile_del.php?sid=".$link."' style='text-decoration:none;background:tan;border:1px solid black;margin: 0 0 0 20px; text-algin:center;'> 删除</a> <a href=\"".$link."\" target=\"_blank\" style='text-decoration:none;background:#ffff33;border:1px solid black;margin: 0 0 0 20px; text-algin:center;'>详情</a></p>";
							}
						}
					}
				}
			}
		}
	
	}
	@closedir($dir);
	if($feekback){
		return $files;
	}
}
function print_dir_img($dir)
{
	$files = array();
	//print_r(opendir( $dir ));
	
	if ( $dw = opendir( $dir ) )
	{
		while (($ctt = readdir($dw)) !== false)
		{
			$pat = "/^[0-9]+$/";
			if(preg_match($pat,$ctt))
			{
				$furl = $dir."/".$ctt;
				if ( $fs = opendir( $furl ) )
				{
					while(($fscan = readdir($fs)) !== false)
					{
						if(strlen($fscan)>3)
						{
							$link = $furl."/".$fscan;
							$tmp = $fscan;
							$filename = explode(".",$tmp);
							$stem = $filename[0];
							echo"<a href='javascript:void(0);' onclick=\"img('".$link."')\"'><img src='".$link."'></a>";
							//echo"<p><a href='".$link."' style='text-decoration:none;background:lime;border:1px solid black;'>[ ".$ctt." ] ".$stem."</a>";
							//echo"<a><a href='upfile_del.php?sid=".$link."' style='text-decoration:none;background:tan;border:1px solid black;margin: 0 0 0 20px; text-algin:center;'> 删除</a></p>";
						}
					}
				}
			}
		}

	}
	@closedir($dir);
}
function print_dir_table($dir)
{
	$files = array();
	//print_r(opendir( $dir ));
	header('Content-type: text/html; charset=GBK');
	if ( $dw = opendir( $dir ) )
	{
		echo '<table border="1" algin="center"><tr><th>序号</th><th>上传日期</th><th>文件名</th><th>文件路径</th></tr>';
		$i = 0;
		while (($ctt = readdir($dw)) !== false)
		{
			$pat = "/^[0-9]+$/";
			if(preg_match($pat,$ctt))
			{
				$furl = $dir."/".$ctt;
				if ( $fs = opendir( $furl ) )
				{
					while(($fscan = readdir($fs)) !== false)
					{
						if(strlen($fscan)>3)
						{
							$link = $furl."/".$fscan;
							$i ++;
							echo '<tr><td>'.$i.'</td><td>'.$ctt.'</td><td>'.$fscan.'</td><td><a href="javascript:void(0);">'.$link.'</a></td></tr>';
						}
					}
				}
			}
		}
		echo '</table>';

	}
	@closedir($dir);
}

function print_deltbale($dir)//一级目录扫描
{
	//header('Content-type: text/html; charset=GBK');
	if(!is_empty_dir($dir)) return false;
	if ( $dw = opendir( $dir ) )
	{
		echo '<table border="1" algin="center"><tr><th>序号</th><th>文件名</th><th>删除</th></tr>';
		$i = 0;
		while(($fscan = readdir($dw)) !== false)
		{
			if(strlen($fscan)>3)
			{
				$i ++;
				echo '<tr><td>'.$i.'</td><td><a href="javascript:void(0);">'.$fscan.'</a></td><td><a href="?file='.$dir.'/'.$fscan.'">删除</a></td></tr>';
			}
		}
		if($i != 0)
		{
			echo '<tr><td>'.($i+1).'</td><td colspan="2"><a href="?file=ALL">一键删除</a></td></tr>';
		}
		echo '</table>';
	}
	@closedir($dir);
}
function deleteAll($dir)//删除一级目录的所有子文件
{
	if ( $dw = opendir( $dir ) )
	{
		while(($fscan = readdir($dw)) !== false)
		{
			if(strlen($fscan)>3)
			{
				unlink($dir.'/'.$fscan);
			}
		}
	}
	@closedir($dir);
}
function is_empty_dir($dir)
{
	if ( $dw = opendir( $dir ) )
	{
		$i = 0;
		while(($fscan = readdir($dw)) !== false)
		{
			++ $i;
		}
	}
	@closedir($dir);
	if($i == 0)
	{
		return true;
	}
	return false;
}




function read_child($node)//应用 【脚本之家函数-读取xml】，测试使用
{ 
	$children = $node->childNodes; //获得$node的所有子节点 
	foreach($children as $e) //循环读取每一个子节点 
	{ 
		if($e->nodeType == XML_TEXT_NODE) //如果子节点为文本型则输出 
		{ 
			echo $e->nodeValue.'<BR>'; 
		} 
		else if($e->nodeType == XML_ELEMENT_NODE) //如果子节点为节点对象，则调用函数处理 
		{ 
			read_child($e); 
		} 
	} 
} 
//~~~~~~~~~~~~~~~~http://jingyan.baidu.com/article/154b46315e74af28ca8f4137.html  存在问题
//腾讯地址信息		
function searchip(){ 
    $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.getIp(); 
    $ch = curl_init($url); 
    curl_setopt($ch,CURLOPT_ENCODING ,'gb2312'); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 
    $result = curl_exec($ch); 
    $result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换，否则乱码 
    curl_close($ch); 
    preg_match("@<span>(.*)</span></p>@iU",$result,$ipArray); 
    $loc = $ipArray[1]; 
    return $loc; 
} 
//新浪地址信息
function sina(){ 
    $url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.getIp(); 
    $ch = curl_init($url); 
    //curl_setopt($ch,CURLOPT_ENCODING ,'utf8'); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回 
    $location = curl_exec($ch); 
    $location = json_decode($location); 
    curl_close($ch);   
    $loc = ""; 
    if($location===FALSE) return ""; 
    if (empty($location->desc)) { 
        $loc = $location->province.$location->city.$location->district.$location->isp; 
    }else{ 
        $loc = $location->desc; 
    } 
    return $loc; 
} 
//createfile 仅仅用于生成文件限于普通文本文件		2016/4/21 星期四
function crtfile($filename)
{
	$fhandle = fopen($filename,'w');
	fclose($fhandle);
	//fclose(fopen($filename,'w'));
}
//获取服务器的信息	2016/4/29 星期五
function server()
{
	//session保存分析值
	if(isset($_SESSION['server_ipconfig'])) return $_SESSION['server_ipconfig'];
	$sys_charset = 'GB2312';//计算机系统编码 , 简体中文  GB2312
	$charset = 'UTF-8';
	if(defined('CHARSET')) $charset = CHARSET;
	$ipconfig = `ipconfig/all`;
	$ipconfig = iconv($sys_charset,'UTF-8',$ipconfig);
	//debug(nl2br($ipconfig),'test.loop');
	//echo nl2br($ipconfig);
	//写入日志
	/*
	$log = "`````````````````````````````Start@_".date('Y-m-d H:i:s')."````````````````````````````````````\n";
	$log .= $ipconfig;
	$log .= "\n`````````````````````````````````````````````````````——".getIp()."^END``````````````````````````````````````\n";
	*/
	$log = "`````````````````````````````Sysfile@_V160504````````````````````````````````````\n";
	$log .= (isMobile()? '[Mobile]':'[Web]').' 时间： '.date('Y-m-d H:i:s').',来源IP： '.getIp().',代理信息： '.$_SERVER["HTTP_USER_AGENT"];
	$log .= "\n";
	console(SYS.'sysfile/log/server_visit.log',$log);
	$ipStr = str_replace('<br>','$',str_replace('<br />','$',nl2br($ipconfig)));
	$ipInfo = array_unull(explode('$',$ipStr),true);
	$ipInfo = array_unull($ipInfo,true);
	$_SESSION['server_ipconfig'] = $ipInfo;
	return $ipInfo;
}
function server_json($standar=false)
{
	if($standar && isset($_SESSION['server_ipconfig_std_json'])) return $_SESSION['server_ipconfig_std_json'];
	elseif(isset($_SESSION['server_ipconfig_json']) && false == $standar) return $_SESSION['server_ipconfig_json'];
	$server = server();
	$them = array();
	$tmpArr = array();
	$json = array();
	//$them = array('Windows IP','无线局域网适配器','以太网适配器','隧道适配器');//主题模板
	//归一化
	foreach($server as $k=>$v)
	{
		if(substr_count($v,'Windows IP')>0 || substr_count($v,'windows ip')>0){
			$server[$k] = '$'.$k;
			$them[$k] = $v;
		}else if(substr_count($v,'网适配器')>0 || substr_count($v,'隧道适配器')>0){
			$server[$k] = '$'.$k;
			$them[$k] = $v;
		}
	}
	$serStr = array_unull(explode('$',implode('@',$server)));//重新划分数组
	foreach($serStr as $kk=>$vv)
	{
		$tmpArr = explode('@',$vv);
		$th_k = $tmpArr[0];
		if(isset($them[$th_k])){
			array_shift($tmpArr);
			foreach($tmpArr as $t_k=>$t_v)
			{
				$t_v = explode('. :',$t_v);
				unset($tmpArr[$t_k]);
				$t_v[0] = trim(str_replace('.','',$t_v[0]));
				if($t_v[0])
					$tmpArr[$t_v[0]] = $t_v[1];
			}
			$json[$them[$th_k]] = $tmpArr;
		}
	}
	//echo '<pre>';print_r($json);return;
	//WLAN Adapter
	$_SESSION['server_ipconfig_json'] = $json;
	if(!$standar) return $json;
	$json_std = array();
	$windows_ip = array('主机名'=>'host_name','主 DNS 后缀'=>'host_dns_suffix','节点类型'=>'type','IP 路由已启用'=>'ip_routing','WINS 代理已启用'=>'wins_proxy');
	$wlan_adapter = array('媒体状态'=>'media_status','连接特定的 DNS 后缀'=>'c_dns_suffix','描述'=>'descript','物理地址'=>'mac_addr','DHCP 已启用'=>'dhcp_able','自动配置已启用'=>'auto_config');
	$ethernet_adapter = array_merge($wlan_adapter,array('本地链接 IPv6 地址'=>'IPv6','IPv4 地址'=>'IPv4','子网掩码'=>'subnet_mask','获得租约的时间'=>'get_lease_tm','租约过期的时间'=>'over_lease_tm','默认网关'=>'default_gateway','DHCP 服务器'=>'dhcp_server','DHCPv6 IAID'=>'dhcpv6_iaid','DHCPv6 客户端 DUID'=>'dhcpv6_duid','DNS 服务器'=>'dns_server','TCPIP 上的 NetBIOS'=>'tcpip_netbios'));
	foreach($json as $k=>$v)
	{
		if(substr_count($k,'Windows IP')>0 || substr_count($k,'windows ip')>0)
		{
			unset($json[$k]);
			//$json['windows_ip'] = $v;
			foreach($v as $kk=>$vv)
			{
				if($windows_ip[$kk]){
					unset($v[$kk]);
					$kk = $windows_ip[$kk];
					$v[$kk] = $vv;
				}
			}
			$json_std['windows_ip'] = $v;
		}else if(substr_count($k,'网适配器')>0 || substr_count($k,'隧道适配器')>0){
			if(substr_count($k,'无线局域网适配器')>0){
				$tpl_key = 'wlan_adapter';
			}elseif(substr_count($k,'以太网适配器')>0){
				$tpl_key = 'ethernet_adapter';
			}elseif(substr_count($k,'隧道适配器')>0){
				$tpl_key = 'tunnel_adapter';
			}else{
				$tpl_key = 'ipconfig';
			}
			$tpl_key_no = 1;
			$tpl_key_no_old = $tpl_key;
			while(isset($json_std[$tpl_key])){
				$tpl_key_no = intVal($tpl_key_no)+1;
				$tpl_key = $tpl_key_no_old.$tpl_key_no;
			}
			foreach($v as $kk=>$vv)
			{
				if($ethernet_adapter[$kk]){
					unset($v[$kk]);
					$kk = $ethernet_adapter[$kk];
					$v[$kk] = $vv;
				}
			}
			$json_std[$tpl_key] = $v;
		}
	}
	$_SESSION['server_ipconfig_std_json'] = $json_std;
	return $json_std;
}
//	2016/4/29 星期五 执行window命令
/*
	参考 ： http://blog.csdn.net/yangjun07167/article/details/5603425
	执行情况会造成乱码,gbk无法与utf转码
*/
function cmd($command)
{
	$putOut = '';
	//passthru($command,$putOut);//??问题 输出结果无法转码
	system($command,$putOut);
	return $putOut;
}
function debug($str,$file=null)
{
	//$file = $file? $file : date('YmdHis');
	$file = $file? $file : date('Y-m-d').'.debug';
	$file = DEBUG.$file;
	if(is_file($file)){
		$str = "\n(".date('Y-m-d H:i:s').")^_^ System-Debug----------------------->\n".$str;
		return console($file,$str);
	}
	else
		file_put_contents($file,$str);
}
//2016/4/29 星期五  文件写入方式，封装fwrite函数
function console($file,$str,$mode='a')
{
	if(fopen($file,$mode)){
		$fh = fopen($file,$mode);
		fwrite($fh,$str);
		fclose($fh);
		return true;
	}
	return false;
}
//删除数组中的空字符	2016/4/29 星期五
function array_unull($array,$order=false)
{
	$arraTpl = array();
	if(is_array($array)){
		foreach($array as $k=>$v){
			$v = trim($v);
			if(is_array($v)) $arraTpl[$k] = array_unull($v);//递归调用   ？？ 算法 ： 递归与迭代
			else if(!empty($v)) $arraTpl[$k] = $v;
			//else if(empty($v)) unset($array[$k]);
		}
		if($order) $arraTpl = array_values($arraTpl);
		return $arraTpl;
	}
	return null;
}
//基于ipconfig命令生成  URL		2016/4/29 星期五
function cro_dns()
{
	$retVal = array();
	$json = server_json(true);
	$n =1;
	foreach($json as $k=>$v)
	{
		if(isset($v['IPv4'])){
			$retVal['d_dns'.$n] = str_replace('ip',trim(str_replace('(首选)',null,$v['IPv4'])),v_dns);
			$n ++;
		}
	}
	//echo '<pre>';print_r($json);
	$retVal['l_dns'] = str_replace('ip','127.0.0.1',v_dns);
	return $retVal;
}
//2016/4/29 星期五 使用该函数调用网站库
function use_libs($name,$option=null)
{
	$_root = dirname(__FILE__);
	$libs = $_root.'/libs/'.$name.'/';
	if(!is_dir($libs)) return '库加载失败,没有找到'.$libs.'目录';
	if(empty($option) && is_file($libs.$name.'.php')){
		require_once($libs.$name.'.php');
		return true;
	}elseif(is_string($option) && (is_file($libs.$option) || is_file($libs.$option.'.php'))){
		$file = is_file($libs.$option)? $libs.$option : $libs.$option.'.php';
		require_once($file);return true;
	}elseif(is_array($option)){
		//foreach($option as $v){use_libs($name,$v);}//递归调用
		foreach($option as $v)//函数遍历调用
		{
			if(is_string($v) && (is_file($libs.$v) || is_file($libs.$v.'.php'))){
				$file = is_file($libs.$v)? $libs.$v : $libs.$v.'.php';
				require_once($file);
			}
		}
	}
}
/*******************************2016/5/4 星期三  移动端与web共同存在**************************************/
//登入时记录登入者信息
function w_logined($obj)
{
	//header('content-type:text/html; charset=gbk;');
	$_SESSION['user'] = SITE_USER;
	$file = virtualDb('data','vtimes.data',true);
	if(is_file($file))
	{
		if($handle = fopen($file,'r+'))
		{
			$vtimes = fgets($handle);
			$vtimeData = json_decode($vtimes,true);
			//$debug = $vtimes."<=\r\n";//获取到的值为空
			$vtimeData["V"] += 1;
			$vtimeStr = json_encode($vtimeData);
			fseek($handle,0);
			fwrite($handle,$vtimeStr);
			//$debug .= "2.\r\n".$vtimeStr;//获取到的值为空
			//debug($debug);
			fclose($handle);
			$isMobile = isMobile();
			$_SESSION['vtimes'] = $vtimeStr;//采用session 存取 json字符串数据
			$wriStr = "\r\n".($isMobile? '[Mobile]' : ' [Web]')."登入时间：".date("Y-m-d H:i:s")."。第".$vtimeData["V"]."次登入系统。IP地址：".getIp()."。\r \n          代理信息：".$_SERVER["HTTP_USER_AGENT"];
			$v_log = ($isMobile? SYS.'sysFile/log/' : '').'vtimes.log';
			$obj->console($wriStr,'N',$v_log);
		}
	}
}
?>